using System;
using System.IO;

using Aspose.Cells;
using System.Drawing;

namespace Aspose.Cells.Examples.CSharp.Data
{
    public class RenameDuplicateColumnsAutomaticallyWhileExportingWorksheetData
    {
        public static void Run()
        {
            // ExStart:RenameDuplicateColumnsAutomaticallyWhileExportingWorksheetData

            //Create a workbook.
            Workbook wb = new Workbook();

            //Access first worksheet.
            Worksheet ws = wb.Worksheets[0];

            //Write the same column name in columns A, B and C.
            string columnName = "People";
            ws.Cells["A1"].PutValue(columnName);
            ws.Cells["B1"].PutValue(columnName);
            ws.Cells["C1"].PutValue(columnName);

            //Insert data in column A, B and C.
            ws.Cells["A2"].PutValue("Data");
            ws.Cells["B2"].PutValue("Data");
            ws.Cells["C2"].PutValue("Data");

            //Create ExportTableOptions and specify that you want to rename 
            //duplicate column names automatically via RenameStrategy property.
            ExportTableOptions opts = new ExportTableOptions();
            opts.ExportColumnName = true;
            opts.RenameStrategy = RenameStrategy.Letter;

            //Export data to data table, duplicate column names will be renamed automatically.
            System.Data.DataTable dataTable = ws.Cells.ExportDataTable(0, 0, 4, 3, opts);

            //Now print the column names of the data table generated by Aspose.Cells while exporting worksheet data.
            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                Console.WriteLine(dataTable.Columns[i].ColumnName);
            }

            // ExEnd:RenameDuplicateColumnsAutomaticallyWhileExportingWorksheetData
        }
    }
}